#!/bin/sh
project_home="/home/nick/workspace/P2PProject/"
port=42000
superNode=""
ip="127.0.1.1"

cd ${project_home}/bin 

max=10 #Max number of peers
maxVisible=10
i=1
while [ $i -le $max ] #Number of peers to create
do
  RANDOM=$(date +%s%N | cut -b1-13)

  porti=$(($port+$i))
  id=P$i
  folder=$project_home/folder/$((($RANDOM%2)+1))
  nrNeighbors=$((($RANDOM%10)+1))
  capacity=$(($RANDOM%3)) #computatinal/bandwith capacity of a node
  
  #create super node
  if [ $i -eq 1 ]
  then
	superNode=$ip":"$porti
  fi
  
  #create super node
  if [ $i -le $maxVisible ]
  then
	xterm -e "java main.Peer $porti $id $nrNeighbors $superNode $capacity $folder" &
  else
   	java main.Peer $porti $id $nrNeighbors $superNode $capacity $folder &
  fi
  
  i=$(($i+1))

  sleep "2"
done
